﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using Kotonoha.Server.Dictionaries;

namespace Kotonoha.Server.UI.Converters {
    class MeaningsConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            // Check for design mode. 
            if ((bool)(DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)) {
                return false;
            }

            IEnumerable<Meaning> meanings = value as IEnumerable<Meaning>;

            if (meanings == null) {
                return "";
            }

            return meanings
                .Select(meaning => meaning.Aggregate((s1, s2) => string.Format("{0},{1}", s1, s2)))
                .Aggregate((s1, s2) => string.Format("{0}/{1}", s1, s2));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            throw new System.NotImplementedException();
        }
    }
}
